// This code is licensed under New BSD Licence. For details see project page at
// http://code.google.com/p/hrissan-cocoa-helpers/source/checkout
#import <Foundation/Foundation.h>
#import "Common.h"

@class FileDownloader;

@protocol FileDownloaderDelegate<NSObject>
- (void) on_start_download:(FileDownloader *)request;
- (void) on_progress_download:(FileDownloader *)request;
- (void) on_complete_download:(FileDownloader *)request;
- (void) on_error_download:(FileDownloader *)request error:(NSError *)error;
- (void) on_write_error:(FileDownloader *)request;
@end


@interface FileDownloader : NSObject
{
	NSPtr<NSString> url;
	NSPtr<NSURLConnection> conn;
	NSPtr<NSFileHandle> file;
	NSObject<FileDownloaderDelegate> * delegate;
	long long offset;
	long long expected_size;
}

+(FileDownloader*) create_with:(NSString *)url path:(NSString *)path delegate:(NSObject<FileDownloaderDelegate>*) delegate;
-(id) initWithURL:(NSString *)url request:(NSURLRequest *) request file:(NSFileHandle *)f delegate:(NSObject<FileDownloaderDelegate>*) delegate;
-(void) cancel;
-(long long)offset;
-(long long)expected_size;
-(NSString *)url;

@end
